package es.wtestgen.test;

import java.util.Iterator;
import java.util.Map;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.persister.entity.EntityPersister;

import junit.framework.TestCase;

public abstract class HibernateTestBase extends TestCase {

	protected Session session;
	protected SessionFactory sessionFactory;

	public HibernateTestBase(){
		
	}
	
	protected void setUp() throws Exception {
	   super.setUp();
	   //Configuration config = new Configuration().configure("/hibernate-test.cfg.xml");
	   //Configuration config = new Configuration().configure("/hibernate.cfg.xml");
	   Configuration config = new Configuration().configure("/hibernate.cfg.xml");
	   sessionFactory = config.buildSessionFactory();
	   session = sessionFactory.openSession();
	}
	
	protected void tearDown() throws Exception {
	   super.tearDown();
	   session.close();
	   sessionFactory.close();
	}
	
	public void testHibernate(){
		Map metadata = sessionFactory.getAllClassMetadata();
		for (Iterator it = metadata.values().iterator(); it.hasNext();) {
			EntityPersister persister = (EntityPersister) it.next(); 
			Query q = session.
			createQuery("from " + persister.getClass().getName() + " c");
			q.iterate();
		}
		assertTrue(true);		
	}
		
	public static void main( String args[] ) {
	      junit.textui.TestRunner.run( HibernateTestBase.class );
	   }
	
	
	
}